package com.icbc.DataStructuresAndAlgorithms;

import org.junit.Test;

public class paoShiTou {
	@Test
	public void test(){
		String s = "XXXXXXX.XXX.X..";
		int leng = leng(0, s.toCharArray());
		System.out.println(leng);
	}
	
	public int leng(int n, char[] cs){
		int len = 0;
		for (int i = n; i < cs.length; i++) {
			int ll = getleng(i, cs);
			if (ll > len) {
				len = ll;
			}
		}
		return len;
	}
	
	public int getleng(int l,char[] cs){
		int sumlen = 0;
		for (int a = l + 1 ; a > 0 ; a /= 2) {
			sumlen += a;
			if (sumlen > cs.length) {
				return 0;
			}
			if (cs[sumlen - 1] == 'X') {
				return 0;
			}
		}
		return sumlen;
	}
	
	@Test
	public void test1(){
		String s = "...............";
		int i = maxDistance(s);
		System.out.println(i);
	}
	
	int maxDistance(String water) {
		int n=water.length()/2+1;
		boolean ok=true;
		int temp,result=0;
		char[] str=water.toCharArray();
		for(int i=n;i>0;i--) {
			ok=true;
			temp=i;
			result=i;
			while (temp>=1) {
				if (str[result-1]=='X') {
					ok=false;
					break;
				}
				temp=temp/2;
				result+=temp;
			}
			if (ok) {
				break;
			}
		}
		return result;
	}
}
